@extends('layout.master')

@section('title','提现列表')

@section('css')
    @parent
    <!-- Daterange picker plugins css -->
    <link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
@endsection
@section('main')

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">拒绝理由</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <input id="id-edit" name="id" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="check-content" name="check_content"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">理由</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-refuse"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>


    <div class="modal fade" id="agree" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">填写快递信息</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels express">
                        <input id="id-edit-agree" name="id" type="hidden" value="">
                        <fieldset style="border:0;">
                            <input type="text" class="form-control" id="name" readonly/><span
                                    class="highlight"></span>
                            <input type="text" class="form-control" id="phone" readonly><span
                                    class="highlight"></span>
                            <input type="text" class="form-control" id="address" readonly><span
                                    class="highlight"></span>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="express-name" name="express_name"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">快递名称</label>
                            </div>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="express-order" name="express_order"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">快递单号</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-agree"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="check" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <form class="floating-labels express">
                        <fieldset style="border:0;">
                            <input type="text" class="form-control" id="name-check" readonly/><span
                                    class="highlight"></span>
                            <input type="text" class="form-control" id="phone-check" readonly><span
                                    class="highlight"></span>
                            <input type="text" class="form-control" id="address-check" readonly><span
                                    class="highlight"></span>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="panel">
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <form action="#">
                    <div class="form-body">
                        <div class="row">
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">提现ID</label>
                                    <input type="text" id="id" class="column_filter form-control"
                                           data-column="0"
                                           placeholder="提现ID">
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">用户手机号</label>
                                    <input type="text" id="mobile" class="column_filter form-control"
                                           data-column="1"
                                           placeholder="用户手机号">
                                </div>
                            </div>
                            <div class="col-xs-3 col-md-3">
                                <div class="form-group">
                                    <label for="status">类型</label>
                                    <select class="form-control column_filter"
                                            data-column="2">
                                        <option value="a">全部</option>
                                        <option value="1">实物</option>
                                        <option value="2">微信</option>
                                        <option value="3">其他</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">提现时间</label>
                                    <div class="example">
                                        <input class="column_filter form-control input-daterange-datepicker" type="text" data-column="3" name="time"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="panel">
        <div class="panel-heading">提现列表</div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-action" style="margin-top: -9px">
                <button class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c all-wechat">
                    <span>微信批量</span>
                </button>
                <button class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c all-ali">
                    <span>支付宝和话费批量</span>
                </button>
            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="example23" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url(request()->getUri()) }}">
                        <thead>
                        <tr>
                            <th></th>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>用户手机号</th>
                            <th>支付宝账号</th>
                            <th>提现类型</th>
                            <th>数量</th>
                            <th></th>
                            <th>状态</th>
                            <th>申请时间</th>
							<th>提现时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <!--<script src="{{ asset('js/myself.js') }}"></script>-->
    <script>
        $('.input-daterange-datepicker').daterangepicker({});
    </script>
    <script>
	
	var obj = $('#example23');
	var url = obj.data('url');
	obj.DataTable({
		dom: 'Bfrtip',
		buttons: [
			'copy', 'csv', 'excel', 'pdf', 'print'
		],
		"bPaginate" : true,
		"bFilter": false,
		"paging": true,
		"ordering": true,
		"processing": true,
		"responsive": false,
		"bLengthChange": true,
		"pageLength":50,
		"smartDisplay":true,
		"lengthChange":false,
		"lengthMenu": [
			[10, 20, 50, 100],
			['10 行', '20 行', '50 行', '100 行'] 
		],
		"order": [[0, "desc"]],
		// "columnDefs": [{
		//     orderable: false,
		//     targets: [1,2]
		// }],
		"language": {
			"sProcessing": '<div id="fountainG"><div id="fountainG_1" class="fountainG"></div><div id="fountainG_2" class="fountainG"></div><div id="fountainG_3" class="fountainG"></div><div id="fountainG_4" class="fountainG"></div><div id="fountainG_5" class="fountainG"></div><div id="fountainG_6" class="fountainG"></div><div id="fountainG_7" class="fountainG"></div><div id="fountainG_8" class="fountainG"></div></div>',
			"sLengthMenu": "显示 _MENU_ 项结果",
			"sZeroRecords": "没有匹配结果",
			"sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
			"sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
			"sInfoFiltered": "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix": "",
			"sSearch": "搜索:",
			"sUrl": "",
			"sEmptyTable": "暂无记录",
			"sLoadingRecords": "载入中...",
			"sInfoThousands": ",",
			"oPaginate": {
				"sFirst": "首页",
				"sPrevious": "上一页",
				"sNext": "下一页",
				"sLast": "末页"
			}
		},
		serverSide: true,
		ajax: {
			url: url,
			type: 'POST',
			headers: {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			}
		},
		"deferRender": true
	});
	$('.column_filter').on('change', function () {
		obj.DataTable().column($(this).data('column')).search($(this).val(), false, true).draw();
	});
	//跳转页
	obj.append("  到第 <input type='text' id='changePage' class='input-text' style='width:50px;height:27px'> 页 ");
	var oTable = obj.dataTable();
	$('#changePage').keyup(function (e) {
		if ($(this).val() && $(this).val() > 0) {
			var redirectpage = $(this).val() - 1;
		} else {
			redirectpage = 0;
		}
		oTable.fnPageChange(redirectpage);
	});
	
        $("#btn-refuse").click(function (e) {
            e.preventDefault();
            var id = $('#id-edit').val();
            var check_content = $('#check-content').val();
            swal({
                    title: "",
                    text: "确定不通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/no/' + id,
                        data: {check_content: check_content},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    $('.status' + id).text('审核不通过');
                                    $('.set' + id).text('');
                                });
                            }
                        }
                    })
                }
            );
        });

        function refuse(sid) {
            $("#id-edit").val(sid);
        }

        function agree(sid) {
            $("#id-edit-agree").val(sid);
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: '/operation/realdetail/' + sid,
                type: 'POST',
                success: function (data) {
                    $("#name").val("收货人：" + data.name);
                    $("#phone").val("联系方式：" + data.phone);
                    $("#address").val("收货地址：" + data.address);
                }
            })

        }

        function check(sid) {
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: '/operation/realdetail/' + sid,
                type: 'POST',
                success: function (data) {
                    $("#name-check").val("收货人：" + data.name);
                    $("#phone-check").val("联系方式：" + data.phone);
                    $("#address-check").val("收货地址：" + data.address);
                }
            })

        }


        //发货

        $("#btn-agree").click(function (e) {
            e.preventDefault();
            var id = $('#id-edit-agree').val();
            var express_name = $("#express-name").val();
            var express_order = $("#express-order").val();
            swal({
                    title: "",
                    text: "确定通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/deliver/' + id,
                        data: {express_name: express_name, express_order: express_order},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    $('.status' + id).text('审核通过');
                                    $('.set' + id).text('');
                                });
                            }
                        }
                    })
                }
            );
        });


        obj.on('click', '.btn-on', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/yes/' + id,
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    $('.status' + id).text('审核通过');
                                    $('.set' + id).text('');
                                });
                            }
                        }
                    })
                }
            );
        });

        $(".all-ali").click(function (e) {
            e.preventDefault();
            //复选框
            var ids = [];
            var checks = document.getElementsByClassName("check");

            for (var i = 0; i < checks.length; i++) {
                var _this = checks[i];
                if (_this.checked === true) {
                    ids[i] = _this.dataset.id;
                }
            }
            if (ids.length <= 0) {
                swal('你倒是选啊~~');
                return false;
            }

            swal({
                    title: "",
                    text: "确定修改吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/aliall',
                        type: 'POST',
                        data: {ids: ids},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    for (var j = 0; j < ids.length; j++) {
                                        $('.status' + ids[j]).text('审核通过');
                                        $('.set' + ids[j]).text('');
                                        checks[j].checked = false;
                                    }

                                });
                            }
                        }
                    })
                }
            );
        });


        $(".all-wechat").click(function (e) {
            e.preventDefault();
            //复选框
            var ids = [];
            var checks = document.getElementsByClassName("check");

            for (var i = 0; i < checks.length; i++) {
                var _this = checks[i];
                if (_this.checked === true) {
                    ids[i] = _this.dataset.id;
                }
            }
            if (ids.length <= 0) {
                swal('你倒是选啊~~');
                return false;
            }

            swal({
                    title: "",
                    text: "确定修改吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/allwechat',
                        type: 'POST',
                        data: {ids: ids},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    for (var j = 0; j < data.ids.length; j++) {
                                        $('.status' + data.ids[j]).text('审核通过');
                                        $('.set' + data.ids[j]).text('');
                                        checks[j].checked = false;
                                    }

                                });
                            }
                        }
                    })
                }
            );
        });

    </script>
@endsection